package com.george.normal.service;


import cn.hutool.core.util.RandomUtil;
import com.george.normal.dao.ProductDao;
import com.george.normal.entity.ProductEntity;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Slf4j
@Service
public class ProductServiceImpl implements ProductService{

    @Autowired
    private ProductDao productDao;


    @PostConstruct
    public void init(){
        Date now = new Date();
        long count = productDao.count(null);
        System.out.println("初始化数据,当前数据量:" + count);
        for (int i = 0; i < 10; i++) {
            ProductEntity entity = new ProductEntity();
            entity.setProductNumber(Long.parseLong(RandomUtil.randomNumbers(10)));
            entity.setProductName("产品" + i);
            entity.setCreateTime(now);
            entity.setUpdateTime(now);
            productDao.save(entity);
        }
        System.out.println("初始化数据成功");
    }


}
